package com.ltxtiyu.video.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.ltxtiyu.video.entity.sjs.SjsClub;
import com.ltxtiyu.video.service.ms.SjsService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


@RequestMapping("sjs")
@Controller
public class SjsController {
    @Reference
    private SjsService sjsService;

    /**
     * 将篮同学视频迁移至短视频库中
     *
     * @return
     */
    @RequestMapping("transferVideo")
    public ResponseEntity transferVideo(Integer club, String startTime, String endTime,Integer publisher) {
        try {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date startTimeDate = format.parse(startTime);
            Date endTimeDate = format.parse(endTime);
            boolean flag = sjsService.transferVideo(club, startTimeDate, endTimeDate,publisher);
            if (flag) {
                return new ResponseEntity(HttpStatus.CREATED);
            } else {
                return new ResponseEntity(HttpStatus.NO_CONTENT);

            }
        } catch (Exception e) {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("异常情况");
        }
    }

    /**
     * 查询所有俱乐部
     *
     * @return
     */
    @RequestMapping("selectAllClub")
    public ResponseEntity selectAllClub() {
        try {
            List<SjsClub> clubList = sjsService.selectAllClub();
            return new ResponseEntity(clubList, HttpStatus.OK);
        } catch (Exception e) {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("异常情况");
        }
    }
}
